package com.vinoxm.common.base.result;

import lombok.Data;
import lombok.Getter;

import java.util.List;

public class HandleResult<T> extends BaseResult {
    @Getter
    private List<T> complete;
    @Getter
    private final List<FailedJson> failed;
    @Getter
    private final int handleRows;

    public List<T> completeAndRemove() {
        List<T> list = complete;
        this.complete = null;
        return list;
    }

    public HandleResult(int handleRows, List<T> complete, List<FailedJson> failed) {
        super(BaseResult.SUCCESS, "Success!");
        this.handleRows = handleRows;
        this.complete = complete;
        this.failed = failed;
    }

    @Data
    public static class FailedJson {
        private final String message;
        private final String reason;

        public FailedJson(String message, String reason) {
            this.message = message;
            this.reason = reason;
        }

        public static FailedJson noSuchHandler(String message) {
            return new FailedJson(message, "No such handler found!");
        }

        public static FailedJson fetchUrlError(String message) {
            return new FailedJson(message, "Fetch url error!");
        }
    }

}
